package com.woniu.project.core.exception;

/**
 * 异常情况的枚举
 * @Author: Klaus
 * @Date: 2020/9/27 19:06
 */
public enum ProjectExceptionCode {
    SYS_URL_NOT(404,"访问的资源不存在"),

    PARAMETER_ERROR(1001,"参数错误"),
    PARAMETER_EMPTY(1002,"参数为空"),
    PARAMETER_INCOMPLETE(1003,"参数不完整"),
    PARAMETER_TYPE_ERROR(1004,"参数类型错误"),
    PARAMETER_INVALID(1005,"参数无效"),

    USER_AUTHE_MESSAGECODE_ERROR(2000,"验证码错误"),
    USER_AUTHE_ERROR(2001,"用户名或密码错误"),
    USER_AUTHE_TOKEN_PARSE(2002,"TOKEN解析错误"),
    USER_AUTHE_TOKEN_EXPIRE(2003,"TOKEN已过期"),
    USER_AUTHE_NOTLOGIN(2004,"用户未登录"),
    USER_AUTHE_DISABLED(2005,"用户已被禁用"),
    USER_REGISTERED(2006,"用户已存在"),
    USER_NOTFOUND(2007,"用户不存在"),
    USER_SAMESTATUS(2008,"用户状态与需要修改的状态一致，无需修改"),
    USER_PASSWORD_SAME(2009,"新旧密码一致，无需修改"),
    USER_PASSWORD_ERROR(2010,"输入的密码有误"),
    USER_ROLENAME_REGISTERED(2011,"角色名已存在"),
    USER_UNAUTHORIZED(403,"用户未授权"),

    STORE_REGISTERED(3000,"仓库名称已存在"),
    STORE_NOTFOUND(3001,"仓库不存在"),

    SENTINEL_BLOCK(4001,"资源限流"),

    JSON_PARSE(3001,"JSON解析错误"),

    SYS_ERROR(500,"出现异常"),

    LOCK_ERROR(5001,"加锁失败");

    private Integer code;

    private String msg;

    ProjectExceptionCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static String getMsg(Integer code) {
        ProjectExceptionCode[] businessModeEnums = values();
        for (ProjectExceptionCode projectExceptionCode : businessModeEnums) {
            if(projectExceptionCode.code.equals(code)){
                return projectExceptionCode.msg;
            }
        }
        return null;
    }
}
